#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    unsigned char buffer[100];
    int fd;
    int ret = 0;

    fd = open(argv[1], O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
    if(-1 == fd){
        perror("open error");
        exit(-1);
    }

    ret = pread(fd, buffer, sizeof(buffer), 1024);
    if(-1 == ret){
        perror("pread error");
        goto err;
    }

    ret = lseek(fd, 0, SEEK_CUR);
    if(-1 == ret){
        perror("lseek error");
        goto err;
    }

    printf("Current Offset: %d\n", ret);

    err:
        close(fd);
        exit(ret);

    close(fd);
    exit(0);
}
